package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysUserJudges;
import com.ruoyi.system.domain.SysUsers;
import com.ruoyi.system.domain.mongodb.Users;
import com.ruoyi.system.mongo.StudentDao;
import com.ruoyi.system.service.ISysUsersService;
import com.ruoyi.system.service.SysUserJudgesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 柳
 * @Date 2021/3/26
 * @Description TODO
 */
@RestController
@RequestMapping("/system/judges")
public class SysUserJudgesController {
    @Autowired
    private SysUserJudgesService sysUserJudgesService;

    @Autowired
    private StudentDao studentDao;

    @Autowired
    private ISysUsersService usersService;

    /**
     * 发送邀请生成一条教师邀请信息
     * @param sysUserJudges
     */
    @PostMapping("/saveSysUserJudgesMapper")
    @ApiOperation("发送邀请生成一条教师邀请信息")
    public AjaxResult saveSysUserJudgesMapper(SysUserJudges sysUserJudges) {
        sysUserJudgesService.saveSysUserJudgesMapper(sysUserJudges);
        return AjaxResult.success();
    }

    /**
     * 修改邀请状态为已拒绝
     * @param jid
     */
    @PutMapping("/updateStateRefuse/{jid}")
    @ApiOperation("修改邀请状态为已拒绝")
    public AjaxResult updateStateRefuse(@PathVariable Integer jid) {
        sysUserJudgesService.updateStateRefuse(jid);
        return AjaxResult.success();
    }


    /**
     * 修改邀请状态为已接受
     * @param sysUserJudges
     */
    @PutMapping("/updateStateAccept")
    @ApiOperation("修改邀请状态为已接受")
    public AjaxResult updateStateAccept(SysUserJudges sysUserJudges) {
//        //获取最后增加的Id
//        long lastUserId = usersService.readLastUserId();
//        //新增联合表
//        usersService.insertUserEvent(lastUserId,sysUserJudges.getEpid().toString());
        //修改邀请状态
        sysUserJudgesService.updateStateAccept(sysUserJudges.getJid());
        return AjaxResult.success();
    }


    //批量添加用户成为评委
    @RequestMapping("insertSysUserJudges")
    public Integer insertSysUserJudges(String userIds,Integer epid,String epstage){
        return sysUserJudgesService.insertSysUserJudges(userIds,epid,epstage);
    }
    //批量添加老师成为评委
    @RequestMapping("invokeTeacherToJudges")
    public Integer invokeTeacherToJudges(String userIds,Integer epid,String epstage){
        return sysUserJudgesService.invokeTeacherToJudges(userIds,epid,epstage);
    }

    //根据id 删除评委
    @RequestMapping("deleteByJid/{jid}")
    public Integer deleteByJid(@PathVariable Integer jid){
        return sysUserJudgesService.deleteByJid(jid);
    }
}
